package com.gupaoedu.springboot.springbootfrist.thirdDemo;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.ArrayList;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 *
 * </p>
 *
 * @author Nicky
 * @since 2019-07-12
 */
public class CacheImportSelect implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        Map<String,Object> attributes = annotationMetadata.getAnnotationAttributes(EnableDefineService.class.getName());

        ArrayList<String> list = new ArrayList<>();
        //根据判断动态注入bean
        if(Objects.requireNonNull(attributes).get("exclude").toString().contains("LogService")){
            list.add(LogService.class.getName());
        }
        else{
            list.add(CacheSevice.class.getName());
        }
        return list.toArray(new String[]{});
    }
}
